package com.xunge.service.impl;

import com.xunge.mapper.EmpMapper;
import com.xunge.mapper.StudentMapper;
import com.xunge.mapper.GradeMapper;
import com.xunge.pojo.JobOption;
import com.xunge.pojo.StudentOption;
import com.xunge.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl  implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private GradeMapper gradeMapper;
    
    @Override
    public JobOption getEmpJobData() {
        //1.统计员工信息
        List<Map<String, Object>> jobData = empMapper.countJobData();

        //2.对获取的信息进行操作封装
        List<Object> jobList = jobData.stream().map(jobdata -> jobdata.get("pos")).toList();
        List<Object> dataList = jobData.stream().map(jobdata -> jobdata.get("num")).toList();

        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countGenderData();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        //1.统计员工信息

        return studentMapper.countDegreeData();
    }

    @Override
    public StudentOption countStudentData() {
        List<Map<String, Object>> StudentData = studentMapper.countStudentData();
        List<Object> clazzList = StudentData.stream().map(clazzData -> clazzData.get("clazzName")).toList();
        List<Object> dataList = StudentData.stream().map(clazzData -> clazzData.get("num")).toList();
        return new StudentOption(clazzList,dataList);

    }


    @Override
    public List<Map<String, Object>> getStudentGenderData() {
        return studentMapper.countStudentGenderData();
    }


    /**
     * 平时成绩分布（合格与不合格人数）
     * @param semester 学期，为空时统计所有学期
     * @return
     */
    @Override
    public List<Map<String, Object>> getGradeUsualData(String semester) {
        return gradeMapper.countGradeDistribution(1, semester); // 1: 平时成绩
    }
    /**
     * 期中成绩分布（合格与不合格人数）
     * @param semester 学期，为空时统计所有学期
     * @return
     */
    @Override
    public List<Map<String, Object>> getGradeMidtermData(String semester) {
        return gradeMapper.countGradeDistribution(2, semester); // 2: 期中成绩
    }

    /**
     * 期末成绩分布（合格与不合格人数）
     * @param semester 学期，为空时统计所有学期
     * @return
     */
    @Override
    public List<Map<String, Object>> getGradeFinalData(String semester) {
        return gradeMapper.countGradeDistribution(3, semester); // 3: 期末成绩
    }

    /**
     * 总评成绩分布（合格与不合格人数）
     * @param semester 学期，为空时统计所有学期
     * @return
     */
    @Override
    public List<Map<String, Object>> getGradeTotalData(String semester) {
        return gradeMapper.countGradeDistribution(4, semester); // 4: 总评成绩
    }

    /**
     * 获取所有学期
     * @return 学期列表
     */
    @Override
    public List<String> getSemesters() {
        return gradeMapper.getSemesters();
    }
}
